package com.ruoyi.spin.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.spin.domain.SpinCoinBean;
import com.ruoyi.spin.service.ISpinCoinBeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * SpinCoin源数据Controller
 *
 * @author stay
 * @date 2023-01-14
 */
@RestController
@RequestMapping("/spin/spin-coin")
public class SpinCoinBeanController extends BaseController {
  @Autowired private ISpinCoinBeanService spinCoinBeanService;

  /** 查询SpinCoin源数据列表 */
  @PreAuthorize("@ss.hasPermi('spin:spin-coin:list')")
  @GetMapping("/list")
  public TableDataInfo list(SpinCoinBean spinCoinBean) {
    startPage();
    List<SpinCoinBean> list = spinCoinBeanService.selectSpinCoinBeanList(spinCoinBean);
    return getDataTable(list);
  }

  /** 导出SpinCoin源数据列表 */
  @PreAuthorize("@ss.hasPermi('spin:spin-coin:export')")
  @Log(title = "SpinCoin源数据", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, SpinCoinBean spinCoinBean) {
    List<SpinCoinBean> list = spinCoinBeanService.selectSpinCoinBeanList(spinCoinBean);
    ExcelUtil<SpinCoinBean> util = new ExcelUtil<SpinCoinBean>(SpinCoinBean.class);
    util.exportExcel(response, list, "SpinCoin源数据数据");
  }

  /** 获取SpinCoin源数据详细信息 */
  @PreAuthorize("@ss.hasPermi('spin:spin-coin:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return success(spinCoinBeanService.selectSpinCoinBeanById(id));
  }

  /** 新增SpinCoin源数据 */
  @PreAuthorize("@ss.hasPermi('spin:spin-coin:add')")
  @Log(title = "SpinCoin源数据", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody SpinCoinBean spinCoinBean) {
    return toAjax(spinCoinBeanService.insertSpinCoinBean(spinCoinBean));
  }

  /** 修改SpinCoin源数据 */
  @PreAuthorize("@ss.hasPermi('spin:spin-coin:edit')")
  @Log(title = "SpinCoin源数据", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody SpinCoinBean spinCoinBean) {
    return toAjax(spinCoinBeanService.updateSpinCoinBean(spinCoinBean));
  }

  /** 删除SpinCoin源数据 */
  @PreAuthorize("@ss.hasPermi('spin:spin-coin:remove')")
  @Log(title = "SpinCoin源数据", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(spinCoinBeanService.deleteSpinCoinBeanByIds(ids));
  }
}
